package com.liam.customer.service;

import com.liam.customer.model.Customer;
import com.liam.helper.DatabaseHelper;
import org.smart4j.framework.annotation.Service;
import org.smart4j.framework.annotation.Transaction;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/14.
 */
@Service
public class CustomerService {
    /**
     * 获取客户列表
     * @param keyword
     * @return
     */
    public List<Customer> getCustomerList(String keyword){
        return DatabaseHelper.queryEntityList(Customer.class,"select * from customer", null);
    }

    /**
     * 获取客户
     * @param id
     * @return
     */
    public Customer getCustomer(long id){
        return DatabaseHelper.queryEntity(Customer.class,"select * from customer where id = ?",id);
    }

    /**
     * 创建客户
     * @return
     */
    @Transaction
    public boolean crateCustomer(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    /**
     * 跟新客户
     * @param id
     * @param fieldMap
     * @return
     */
    @Transaction
    public boolean updateCustomer(long id,Map<String,Object> fieldMap){
        return  DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    /**
     * 删除客户
     * @param id
     * @return
     */
    @Transaction
    public boolean deleteCustomer(long id){
        return  DatabaseHelper.deleteEntity(Customer.class,id);
    }
}
